home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
citydemo
/
c4i_main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-10
|
6KB
|
263 lines
#ifndef lint
static char SccsId[]= "@(#)c4i_main.c V1.9 3/15/95";
#endif
/*------------------------------------------------------------------
| file name -- c4i_main.c
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvtools.h"
#include "Tfundecl.h"
#include "c4i_vars.h"
#include "GRfundecl.h"
#include "VUfundecl.h"
#include "c4i_fundecl.h"
#include "MISCfuns.h"
#ifdef WINNT
#include <windows.h>
#include <crtdbg.h>
ADDRFUNPTR VEdspfunset V_P_((ADDRFUNPTR));
ADDRESS C4I_ErrHandler (char *);
#endif /* WINNT */
#ifndef WINNT
/* Include the X based files so we can add AppTimeOuts */
#ifdef CONST
#undef CONST
#endif
#ifndef __STDC__
#define _NO_PROTO
#endif
/* X11 include files */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#endif /* Not WINNT */
#define SEARCH_PATH (CHAR*)NULL
#define DISPFORM_TABLE (CHAR*)NULL
/* This program can be linked to run:
|
| With 100% CPU usage (which shows updates in a tight loop)
| comment #define DV_USE_TIMER
| With Time-Outs (which show update based on a timer.
| uncomment #define DV_USE_TIMER
*/
#define DV_USE_TIMER
#ifdef DV_USE_TIMER
LOCAL unsigned int TimeoutInterval = 50;
#ifdef WINNT
LOCAL HWND Hwnd;
LOCAL VOID CALLBACK TimeOutProc V_P_((HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime));
#else /*UNIX*/
LOCAL XtAppContext app_context;
LOCAL VOID UpdateProc V_P_((ADDRESS args, XtIntervalId *interval_id));
#endif /* WINNT */
#endif /* DV_USE_TIMER */
/*--------------------------------------------------------------------
| main()
| This module is the basic skeleton of a DataViews application.
|
*/
#ifdef WINNT
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
INT argc = 0;
CHAR **argv;
make_argv(&argc,&argv,GetCommandLine());
#else /* Not WINNT */
int
main (argc, argv)
int argc;
char *argv[];
{
#endif /* WINNT */
/* Initialize arguments, argv[1] - display device */
if (argc > 1)
DeviceName = argv[1];
/* Initialize */
/* DataViews Initializaton */
VUoff_copyright ();
(VOID) TInit (SEARCH_PATH, DISPFORM_TABLE);
#ifdef WINNT
// Register a local error handler
(VOID) VEdspfunset(C4I_ErrHandler);
#endif
InitDataTable (); /* found in c4i_rebind.c */
InitModel (); /* found in c4i_model.c */
InitDisplays (); /* found in c4i_dsp.c */
#ifdef DV_USE_TIMER
#ifdef WINNT
/* Get the Windows based information */
(VOID) GRget (V_WIN32_WINDOW_HANDLE, &Hwnd, V_END_OF_LIST);
/* Post a timeout for dynamic updates
| The timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
SetTimer (Hwnd, (UINT)Hwnd, TimeoutInterval, (TIMERPROC)TimeOutProc);
#else /*UNIX*/
/* Extract the X information so we can setup a Time-Out Proc
| for updating....
| Get the Xt Application Context information.
| Post a timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
(VOID) GRget (V_X_APPLIC_CONTEXT, &app_context, V_END_OF_LIST);
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc)UpdateProc, NULL);
#endif /* WINNT */
#endif /* USE TIMER */
/* Control Loop */
ApplicationState = (DV_BOOL) RUNNING;
while (ApplicationState == RUNNING)
{
#ifndef DV_USE_TIMER
/* Update the Display */
HandleDynamics();
#endif /* DV_USE_TIMER */
/* Gather and Process User Inputs
| Note: since we posted a time-out, the event
| handler will call our function to handle
| the updating of dynamic objects.
*/
HandleEvents (); /* found in c4i_events.c */
}
/* Termination and Clean Up */
TermDisplays (); /* found in c4i_dsp.c */
TermDataTable (); /* found in c4i_rebind.c */
(VOID) TTerminate (); /* DataViews Termination */
return EXIT_OK;
}
#ifdef DV_USE_TIMER
#ifdef WINNT
/*ARGSUSED*/
LOCAL VOID CALLBACK
TimeOutProc (hwnd, uMsg, idEvent, dwTime)
HWND hwnd;
UINT uMsg;
UINT idEvent;
DWORD dwTime;
{
HandleDynamics ();
}
#else /*UNIX*/
/*ARGSUSED*/
LOCAL VOID
UpdateProc (args, interval_id)
ADDRESS args;
XtIntervalId *interval_id;
{
/* Gather and Process Data */
HandleDynamics (); /* found in c4i_dyn.c */
/* Re-Post the Time-Out */
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc) UpdateProc, NULL);
}
#endif /* WINNT */
#endif /* DV_USE_TIMER */
#ifdef WINNT
/*
Special error handler to prevent the following endless cycle:
Error dialog pops up, Dialog gets cancelled, Expose event causes
window redraw, which generates another error dialog.
To break the cycle, we will only display the error message every other
time. If a different message comes in it gets displayed immediately.
If two error messages alternate, then we have a problem..
*/
#define ERRBUFSIZE 500
LOCAL ADDRESS C4I_ErrHandler (char *pErrStr)
{
LOCAL char pLastErrStr[ERRBUFSIZE] = "";
LOCAL BOOL bDispErr = TRUE;
int nStrLen;
_ASSERT(pErrStr != NULL);
// See if old error message is the same as the new one. If not,
// Get its size, save it, & set bDispErr to true so that the
// message gets displayed.
if (strcmp(pLastErrStr,pErrStr) != 0)
{
nStrLen = strlen(pErrStr);
if (nStrLen > ERRBUFSIZE)
nStrLen = ERRBUFSIZE - 1;
strncpy(pLastErrStr,pErrStr, nStrLen);
pLastErrStr[nStrLen] = '\0';
bDispErr = TRUE;
}
// If bDispErr is TRUE, we either have a new message, or it is time
// to display the old one again
if(bDispErr)
{
if(MessageBox(GetFocus(), pErrStr, NULL, MB_OKCANCEL)==IDCANCEL)
S_EXIT(1);
bDispErr = FALSE;
}
else
{
bDispErr = TRUE;
}
return NULL;
}
#endif